package com.cyzy.controller;

import com.cyzy.dto.Result;
import com.cyzy.pojo.Driver;
import com.cyzy.pojo.Passenger;
import com.cyzy.service.DriverService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/driver")
public class DriverController {
    @Autowired
    private DriverService driverService;

    //对用户进行分页查询
    @GetMapping("/page")
    public Result userPageHelper(int page, int size){
        // 启动分页，page表示当前页，size表示每页的记录数
//        PageHelper.startPage(page, size);
        PageHelper.startPage(page,size);
        // 获取分页后的数据
        List<Driver> driverList = driverService.selectDriverList();
        if (driverList.isEmpty()){
            return Result.error().message("暂无数据！");
        }

        PageInfo<Driver> pageInfo = new PageInfo<>(driverList);
//        System.out.println(adminMenuList);
//        System.out.println(pageInfo);
        // 返回分页后的数据列表
        return Result.ok().data("list",driverList).data("count",pageInfo.getTotal());
    }
}
